import pymysql

# 打开数据库连接
db = pymysql.Connect(
    host = '127.0.0.1',
    port = 3306,#必须是数字类型
    user = 'root',
    password = '',
    db = 'test',
    charset = 'utf8'
)
# db = pymysql.connect("localhost","root","","test")
# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()

# print(db)
# 使用 execute()  方法执行 SQL 查询
# cursor.execute("SELECT VERSION()")

#查询数据表多条
def SelectAll(sql):
    try:
        cursor.execute(sql)
        results = cursor.fetchall()
        print(results)
    except:
        db.rollback()
        return ['false']
# db.close()
#c查询一条数据
def SelectOne(sql):
    try:
        cursor.execute(sql)
        results = cursor.fetchone()
        print(results)
    except:
        db.rollback()
        return ['false']


SelectAll("select * from test")